package org.microser.gataway.zuul.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.microser.gataway.zuul.system.entity.Role;
import org.microser.gataway.zuul.system.entity.RolePermission;
import org.microser.gataway.zuul.system.mapper.RolePermissionMapper;
import org.microser.gataway.zuul.system.service.RolePermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liujiamiao
 * @since 2020-11-25
 */
@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements RolePermissionService {

    /**
     * 根据单个角色找到权限
     * @param role
     * @return
     */
    @Override
    public List<String> queryPermisstionIdsByRole(Role role) {
        QueryWrapper<RolePermission> wrapper = new QueryWrapper();
        wrapper.eq("role_id",role.getId());
        wrapper.select("permisstion_id");
        List<RolePermission> list = list(wrapper);
        List<String> ids = list.stream().map(entity -> {
            return entity.getPermisstionId();
        }).collect(Collectors.toList());
        return ids;
    }
}
